package com.xuecheng.media.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xuecheng.media.model.po.MediaProcess;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Mapper
public interface MediaProcessMapper extends BaseMapper<MediaProcess> {
    @Select("select * from media_process where id % #{shardTotal} = #{shardIndex} " +
            "and task_type = #{taskType} and (status = 1 or status = 3) " +
            "and fail_count < 3 limit #{count}")
    List<MediaProcess> selectListByShardIndex(
            @Param("shardIndex") Integer shardIndex,
            @Param("shardTotal") Integer shardTotal,
            @Param("count") Integer count,
            @Param("taskType") String taskType);

    @Update("update media_process set status = 4,begin_date = now() " +
            "where id = #{id} and (status = 1 or status = 3) and fail_count < 3")
    int startTack(Long id);

    @Select("select max(id) from media_process")
    Long getMaxId();
}
